package com.esri.core.internal.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ViewAnimator;

/* loaded from: classes.dex */
public class ViewGallery extends ViewAnimator {
    private static final long f = 250;
    OnEventListener a;
    OnEventListener b;
    OnEventListener c;
    OnEventListener d;
    protected GestureDetector e;
    private OnViewChangeListener g;

    /* loaded from: classes.dex */
    public interface OnEventListener {
        boolean execute(MotionEvent motionEvent);
    }

    /* loaded from: classes.dex */
    public interface OnViewChangeListener {
        boolean execute();
    }

    public void setOnLongPressListener(OnEventListener onEventListener) {
        this.a = onEventListener;
    }

    public void setOnShowPressListener(OnEventListener onEventListener) {
        this.b = onEventListener;
    }

    public void setOnSingleTapListener(OnEventListener onEventListener) {
        this.d = onEventListener;
    }

    public void setOnDoubleTapListener(OnEventListener onEventListener) {
        this.c = onEventListener;
    }

    public void setOnViewChangeListener(OnViewChangeListener onViewChangeListener) {
        this.g = onViewChangeListener;
    }

    public ViewGallery(Context context) {
        super(context);
        this.e = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { // from class: com.esri.core.internal.widget.ViewGallery.1
            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public boolean onDown(MotionEvent motionEvent) {
                return true;
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public void onLongPress(MotionEvent motionEvent) {
                if (ViewGallery.this.a != null) {
                    ViewGallery.this.a.execute(motionEvent);
                }
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public void onShowPress(MotionEvent motionEvent) {
                if (ViewGallery.this.b != null) {
                    ViewGallery.this.b.execute(motionEvent);
                }
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener
            public boolean onDoubleTap(MotionEvent motionEvent) {
                if (ViewGallery.this.c != null) {
                    return ViewGallery.this.c.execute(motionEvent);
                }
                return false;
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener
            public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
                if (ViewGallery.this.d != null) {
                    return ViewGallery.this.d.execute(motionEvent);
                }
                return false;
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float f2, float f3) {
                if (ViewGallery.this.getChildCount() < 2) {
                    return false;
                }
                return a(motionEvent2.getX() - motionEvent.getX());
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float f2, float f3) {
                if (ViewGallery.this.getChildCount() < 2) {
                    return false;
                }
                if (f2 > 10.0f || f2 < -10.0f) {
                    a(f2);
                    return true;
                }
                return true;
            }

            private boolean a(float f2) {
                if (ViewGallery.this.getInAnimation() == null || ViewGallery.this.getOutAnimation() == null || (ViewGallery.this.getInAnimation().hasEnded() && ViewGallery.this.getOutAnimation().hasEnded())) {
                    if (f2 > 0.0f) {
                        ViewGallery viewGallery = ViewGallery.this;
                        viewGallery.setInAnimation(viewGallery.a());
                        ViewGallery viewGallery2 = ViewGallery.this;
                        viewGallery2.setOutAnimation(viewGallery2.b());
                        ViewGallery.this.showNext();
                        return true;
                    }
                    ViewGallery viewGallery3 = ViewGallery.this;
                    viewGallery3.setInAnimation(viewGallery3.c());
                    ViewGallery viewGallery4 = ViewGallery.this;
                    viewGallery4.setOutAnimation(viewGallery4.d());
                    ViewGallery.this.showPrevious();
                    return true;
                }
                return true;
            }
        });
    }

    public ViewGallery(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.e = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { // from class: com.esri.core.internal.widget.ViewGallery.1
            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public boolean onDown(MotionEvent motionEvent) {
                return true;
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public void onLongPress(MotionEvent motionEvent) {
                if (ViewGallery.this.a != null) {
                    ViewGallery.this.a.execute(motionEvent);
                }
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public void onShowPress(MotionEvent motionEvent) {
                if (ViewGallery.this.b != null) {
                    ViewGallery.this.b.execute(motionEvent);
                }
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener
            public boolean onDoubleTap(MotionEvent motionEvent) {
                if (ViewGallery.this.c != null) {
                    return ViewGallery.this.c.execute(motionEvent);
                }
                return false;
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener
            public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
                if (ViewGallery.this.d != null) {
                    return ViewGallery.this.d.execute(motionEvent);
                }
                return false;
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float f2, float f3) {
                if (ViewGallery.this.getChildCount() < 2) {
                    return false;
                }
                return a(motionEvent2.getX() - motionEvent.getX());
            }

            @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener
            public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent2, float f2, float f3) {
                if (ViewGallery.this.getChildCount() < 2) {
                    return false;
                }
                if (f2 > 10.0f || f2 < -10.0f) {
                    a(f2);
                    return true;
                }
                return true;
            }

            private boolean a(float f2) {
                if (ViewGallery.this.getInAnimation() == null || ViewGallery.this.getOutAnimation() == null || (ViewGallery.this.getInAnimation().hasEnded() && ViewGallery.this.getOutAnimation().hasEnded())) {
                    if (f2 > 0.0f) {
                        ViewGallery viewGallery = ViewGallery.this;
                        viewGallery.setInAnimation(viewGallery.a());
                        ViewGallery viewGallery2 = ViewGallery.this;
                        viewGallery2.setOutAnimation(viewGallery2.b());
                        ViewGallery.this.showNext();
                        return true;
                    }
                    ViewGallery viewGallery3 = ViewGallery.this;
                    viewGallery3.setInAnimation(viewGallery3.c());
                    ViewGallery viewGallery4 = ViewGallery.this;
                    viewGallery4.setOutAnimation(viewGallery4.d());
                    ViewGallery.this.showPrevious();
                    return true;
                }
                return true;
            }
        });
    }

    Animation a() {
        TranslateAnimation translateAnimation = new TranslateAnimation(2, 1.0f, 2, 0.0f, 2, 0.0f, 2, 0.0f);
        translateAnimation.setDuration(f);
        translateAnimation.setInterpolator(new AccelerateInterpolator());
        return translateAnimation;
    }

    Animation b() {
        TranslateAnimation translateAnimation = new TranslateAnimation(2, 0.0f, 2, -1.0f, 2, 0.0f, 2, 0.0f);
        translateAnimation.setDuration(f);
        translateAnimation.setInterpolator(new AccelerateInterpolator());
        return translateAnimation;
    }

    Animation c() {
        TranslateAnimation translateAnimation = new TranslateAnimation(2, -1.0f, 2, 0.0f, 2, 0.0f, 2, 0.0f);
        translateAnimation.setDuration(f);
        translateAnimation.setInterpolator(new AccelerateInterpolator());
        return translateAnimation;
    }

    Animation d() {
        TranslateAnimation translateAnimation = new TranslateAnimation(2, 0.0f, 2, 1.0f, 2, 0.0f, 2, 0.0f);
        translateAnimation.setDuration(f);
        translateAnimation.setInterpolator(new AccelerateInterpolator());
        return translateAnimation;
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        return this.e.onTouchEvent(motionEvent);
    }

    @Override // android.widget.ViewAnimator
    public void showNext() {
        super.showNext();
        OnViewChangeListener onViewChangeListener = this.g;
        if (onViewChangeListener != null) {
            onViewChangeListener.execute();
        }
    }

    @Override // android.widget.ViewAnimator
    public void showPrevious() {
        super.showPrevious();
        OnViewChangeListener onViewChangeListener = this.g;
        if (onViewChangeListener != null) {
            onViewChangeListener.execute();
        }
    }

    public void e() {
        OnViewChangeListener onViewChangeListener = this.g;
        if (onViewChangeListener != null) {
            onViewChangeListener.execute();
        }
    }
}
